package com.example.housingRentalSystem.utils;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * @author 王硕
 * @version jdk21
 * @className PageRequest
 * @description
 * @date 2025/3/21 17:31
 */
@Data
public class PageRequest {
    private Integer page = 1;
    private Integer size = 10;
    private String sortField = "create_time";
    private String sortOrder = "DESC";

    /**
     * 校验分页参数
     */
    public void validate() {
        // 参数校验
        page = Math.max(page, 1);
        size = Math.min(Math.max(size, 1), 100);
        if (!"ASC".equalsIgnoreCase(sortOrder) && !"DESC".equalsIgnoreCase(sortOrder)) {
            sortOrder = "DESC";
        }
    }

    public PageRequest() {}
}
